package com.wenhao.binalifeng;

import java.util.*;

/**
 * @author Wenhao Tong
 * @create 2021-09-01 17:57
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        int[] cor = new int[2];
        String c = scanner.nextLine();
        cor[0] = Integer.parseInt(c.substring(0,c.indexOf(',')));
        cor[1] = Integer.parseInt(c.substring(c.indexOf(',') + 1));
        String[] split = s.split(";");
        int[][] list = new int[split.length][2];
        int i = 0;
        int cur = 0;
        visited = new int[list.length];
        for (String t : split) {
            list[i][0] = Integer.parseInt(t.substring(1,t.indexOf(',')));
            list[i][1] = Integer.parseInt(t.substring(t.indexOf(',') + 1,t.length() - 1));
            if (list[i][0] == cor[0] && list[i][1] == cor[1]) {
                visited[i] = 1;
                cur = i;
            }
            i++;
        }
        dfs(list,0,cur,list.length - 1);
        System.out.println(min);
    }

    private static int[] visited;
    private static int min = Integer.MAX_VALUE;
    private static void dfs(int[][] list,int length,int cur,int next) {
        if (next == 0) {
            min = Math.min(min,length);
        }
        for (int i = 0;i < list.length;i++) {
            if (visited[i] == 0) {
                visited[i] = 1;
                dfs(list,length + Math.max(Math.abs(list[cur][0] - list[i][0]),Math.abs(list[cur][1] - list[i][1])),i,next - 1);
                visited[i] = 0;
            }
        }
    }
}
